package cn.gzmli.dtt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@SpringBootApplication
@ServletComponentScan
@ComponentScan(basePackages = "cn.gzmli.dtt.*")
//@MapperScan("cn.gzmli.dtt.dao")\
@EnableTransactionManagement
@EntityScan("cn.gzmli.dtt.*")
public class SbzycAdminApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(SbzycAdminApplication.class, args);
    }

    @Override//为了打包springboot项目
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }

    @Bean
    LocalSessionFactoryBean sessionFactoryBean(DataSource dataSource) {
        LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        sessionFactoryBean.setPackagesToScan("cn.gzmli.dtt.*");
//        Properties properties = new Properties();
    /*    properties.setProperty("dialect", "org.hibernate.dialect.MySQL5Dialect");
        sessionFactoryBean.setHibernateProperties(properties);*/
        return sessionFactoryBean;
    }

}

